import java.io.*;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.ArrayList;

import java.util.List;

public class Retriever {
	
	private Queue<URL> my_queue = new Queue<URL>();
	
	private int count = 0;
	
	private int max = 500;

	public Retriever(URL website) {

		my_queue.enqueue(website);
		
	}

	public void getContent() throws IOException {
		
		URL url = my_queue.dequeue();
		
		StringBuffer content_buffer = new StringBuffer();

		InputStream in;
		
		in = url.openStream();

		int char_offset = in.read();

		while (char_offset != -1) {

			content_buffer.append((char)char_offset);

			char_offset = in.read();
		}
		
		Parser parse = new Parser();
		parse.add(content_buffer.toString());
		parse.parseAnchorTags();

	}
	
	public void Add(URL the_url) {
		
		
		my_queue.enqueue(the_url);
	}
	
	public void Start() {
		
		while(count < max) {
			
			try {
				getContent();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			count++;
		}
		
	}

}